<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchApi"
      :isSelectColumn="false"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="detailHandle(null,'add')">新增</el-button>
      </template>
    </FilterTable>

    <Drawer
      :visible.sync="visibleDrawer"
      title="配件索赔单维护"
      width="80vw"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer>

    <Drawer
      :visible.sync="showDetailFlag"
      title="配件索赔单明细"
      width="80vw"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-detail v-model="initData" @close="infoClose" />
    </Drawer>
  </div>
</template>
  
<script>
import infoDetail from '../query/info';
import infoModel from './info';
import { dictionary } from '@/utils/dictMixin';
import { getClaimData, cancelClaimById } from '@/api/partsmanage/claim/apply';
export default {
  name: 'chaimapplyindex',
  mixins: [dictionary],
  components: {
    infoModel,
    infoDetail
  },
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      // topFilterList: [],
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns(),
      fetchApi: getClaimData,
      tableData: [],
      visibleDrawer: false,
      showDetailFlag: false,
      initData: {}
    }
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    Object.assign({ apply: 'S' }, this.fetchParams)
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '索赔单号:',
          fieldName: 'spddhm'
        },
        // {
        //   type: 'INPUT',
        //   label: '签收单号:',
        //   fieldName: 'student_name'
        // },
        {
          type: 'INPUT',
          label: '采购单号',
          fieldName: 'student_age'
        },
        {
          type: 'SELECT',
          label: '索赔类型:',
          fieldName: 'bssplx',
          placeholder: '请选择...',
          itemList: this.createDictList('5006')
        },
        // { 
        //   type: 'RANGE_DATE',  
        //   label: '创建日期',  
        //   fieldName: 'created_at',
        //   valueFormat: 'yyyy-MM-dd',   
        //   initialValue: [], 
        //   placeholder: '请选择' 
        // },
        {type: 'RANGE_DATE', label: '创建日期', fieldName: 'createdAt1|createdAt2', valueFormat: 'yyyy-MM-dd', placeholder: '请选择'},
        {
          type: 'INPUT',
          label: '经办人:',
          fieldName: 'xtczry'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 150,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'edit')}>
                  编辑
                </multiuse-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.showDetail(props.row,'show')}>
                  明细
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.deleteHandle(props.row,'delete')}>
                  取消
                </el-button>
              </div>
            );
          }
        },
        {
          title: '索赔单号',
          dataIndex: 'spddhm',
          sorter: true,
          width: 160
        },
        {
          title: '采购单号',
          dataIndex: 'cgddhm',
          sorter: true,
          width: 160
        },
        // {
        //   title: '发运单号',
        //   dataIndex: 'student_age',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input'
        // },
        {
          title: '索赔类型',
          dataIndex: 'bssplx',
          sorter: true,
          // width: 100,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.bssplx, '5006')}</span>;
          }
        },
        {
          title: '索赔状态',
          dataIndex: 'xsddzt',
          sorter: true,
          // width: 100,
          render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.xsddzt, '5007')}</span>;
          }
        },
        {
          title: '索赔种类',
          dataIndex: 'sppjzl',
          sorter: true,
          // width: 100
        },
        {
          title: '索赔数量',
          dataIndex: 'sppjsl',
          sorter: true,
          // width: 100
        },
        {
          title: '索赔金额',
          dataIndex: 'bsspze',
          sorter: true,
          // width: 100
        },
        {
          title: '经办人',
          dataIndex: 'xtczry',
          sorter: true,
          // width: 100
        },
        {
          title: '创建日期',
          dataIndex: 'created_at',
          sorter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          width: 150
        }
      ];
    },
    changeHandle(val) {
      val.createdAt2 && (val.createdAt2 = val.createdAt2.split(' ')[0] + ' 23:59:59');
      this.fetchParams = Object.assign({}, val, { apply: 'S', xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(row,type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.showDetailFlag = false;
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    deleteHandle(row,type) {
      this.$confirm('确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(() => {
        var xsddzt = row.xsddzt
        if (xsddzt === 'F') {
          this.$notify.error({ title: '提示信息', message: '该单据已作废' || '操作失败!' });
          return false;
        }
        if (xsddzt === 'P') {
          this.$notify.error({ title: '提示信息', message: '该单据已审批通过' || '操作失败!' });
          return false;
        }
        var spid = row.id
        cancelClaimById(spid).then(response => {
          if (response.resultCode === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        })
      })
      .catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    showDetail(row,type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.showDetailFlag = true;
    }
  }
}
</script>